package com.aiyige.page.photo.model;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by zhuyakun on 2017/12/20.
 */

public class PhotoDetail implements Parcelable {
    List<Photo> photoList;
    String title;
    String goodsId;
    boolean localPhoto;
    int playIndex;

    public PhotoDetail() {
    }

    private PhotoDetail(Builder builder) {
        setPhotoList(builder.photoList);
        setTitle(builder.title);
        setGoodsId(builder.goodsId);
        setLocalPhoto(builder.localPhoto);
        setPlayIndex(builder.playIndex);
    }

    public static Builder newBuilder() {
        return new Builder();
    }

    public List<Photo> getPhotoList() {
        return photoList;
    }

    public void setPhotoList(List<Photo> photoList) {
        this.photoList = photoList;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public boolean isLocalPhoto() {
        return localPhoto;
    }

    public void setLocalPhoto(boolean localPhoto) {
        this.localPhoto = localPhoto;
    }

    public int getPlayIndex() {
        return playIndex;
    }

    public void setPlayIndex(int playIndex) {
        this.playIndex = playIndex;
    }

    public static final class Builder {
        private List<Photo> photoList;
        private String title;
        private String goodsId;
        private boolean localPhoto;
        private int playIndex;

        private Builder() {
            photoList = new LinkedList<>();
            title = "";
            goodsId = "";
            localPhoto = false;
            playIndex = 0;
        }

        public Builder photoList(List<Photo> val) {
            photoList = val;
            return this;
        }

        public Builder title(String val) {
            title = val;
            return this;
        }

        public Builder goodsId(String val) {
            goodsId = val;
            return this;
        }

        public Builder localPhoto(boolean val) {
            localPhoto = val;
            return this;
        }

        public Builder playIndex(int val) {
            playIndex = val;
            return this;
        }

        public PhotoDetail build() {
            return new PhotoDetail(this);
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeTypedList(this.photoList);
        dest.writeString(this.title);
        dest.writeString(this.goodsId);
        dest.writeByte(this.localPhoto ? (byte) 1 : (byte) 0);
        dest.writeInt(this.playIndex);
    }

    protected PhotoDetail(Parcel in) {
        this.photoList = in.createTypedArrayList(Photo.CREATOR);
        this.title = in.readString();
        this.goodsId = in.readString();
        this.localPhoto = in.readByte() != 0;
        this.playIndex = in.readInt();
    }

    public static final Creator<PhotoDetail> CREATOR = new Creator<PhotoDetail>() {
        @Override
        public PhotoDetail createFromParcel(Parcel source) {
            return new PhotoDetail(source);
        }

        @Override
        public PhotoDetail[] newArray(int size) {
            return new PhotoDetail[size];
        }
    };
}
